﻿using System.Windows.Forms;

namespace MetadataDocumentationGenerator.DelegatesHelpers
{
    class ComboBoxDelegates
    {
        public static void SetEnableState(ComboBox cbb, bool enabled)
        {
            MethodInvoker mi = delegate
            {
                cbb.Enabled = enabled;
            };

            if (cbb.InvokeRequired)
            {
                cbb.Invoke(mi);
            }
            else
            {
                mi();
            }
        }

        public static void AddItem(ComboBox cbb, object o)
        {
            MethodInvoker mi = delegate
            {
                cbb.Items.Add(o);
            };

            if (cbb.InvokeRequired)
            {
                cbb.Invoke(mi);
            }
            else
            {
                mi();
            }
        }

        public static void SetSelectedIndex(ComboBox cbb, int index)
        {
            MethodInvoker mi = delegate
            {
                cbb.SelectedIndex = index;
            };

            if (cbb.InvokeRequired)
            {
                cbb.Invoke(mi);
            }
            else
            {
                mi();
            }
        }

        public static ComboBox.ObjectCollection GetItems(ComboBox cbb)
        {
            ComboBox.ObjectCollection items = null;

            MethodInvoker mi = delegate
            {
                items = cbb.Items;
            };

            if (cbb.InvokeRequired)
            {
                cbb.Invoke(mi);
            }
            else
            {
                mi();
            }

            return items;
        }

    }
}